using UnityEngine;

public class EntityLogicBase:MonoBehaviour
{
    [HideInInspector]
    public Transform render;

    [HideInInspector]
    public float _walkSpeed = 1f;

    [HideInInspector]
    public float _runSpeed = 5f;

    [HideInInspector]
    public float _airMoveSpeed = 3;

    [HideInInspector]
    public float _fallSpeedMax = -50;//-50;

    public float Vy = 0f;
    public float _jumpSpeed = 20f;//6;
    public float _gravity = -9.81f;//-25;

    public float groundY;


    public OnGroundSensor onGroundSensor;

    public void StarJump()
    {

    }
    public void RestVy()
    {
        Vy = _jumpSpeed;
        groundY = transform.position.y;
    }

    public void FinshJump()
    {
        groundY = 0;
    }


    public virtual void Behit(EntityLogicBase DamageSource,int DamageValue)
    {
        if (DamageSource == null) return;
        Vector3 dire = transform.position - DamageSource.transform.position;
        Vector3 modelDire = render.Find("ybot").transform.forward;

        float angle = Vector3.Angle(dire, modelDire);
        if(angle>-90 && angle <0 || angle >0 && angle < 90) //背向
        {
            render.GetComponentInChildren<Animator>().SetTrigger("behit2");
        }
        else
        {
            render.GetComponentInChildren<Animator>().SetTrigger("behit1");
        }
    }


    public virtual void OnInit(object userData = null)
    {
        render = transform.parent.Find("render");
        onGroundSensor = transform.Find("root").Find("sensor").GetComponent<OnGroundSensor>();
        onGroundSensor.Init(transform.Find("root").Find("shenti"));
        _walkSpeed = 2f;
        _runSpeed = 5f;
        groundY = transform.position.y;

    }


}